package com.ithaohao.controller;


import com.ithaohao.pojo.Application;
import com.ithaohao.pojo.Invitations;
import com.ithaohao.pojo.Result;


import com.ithaohao.service.InvitationsService;


import jakarta.servlet.http.HttpSession;
import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


import java.util.List;

@RestController
@Slf4j
@RequestMapping("/invitations")
public class InvitationsController {
    @Autowired
    private InvitationsService invitationsService;

    /* 用户已登录
      发布邀请函*/
    @PostMapping
    public Result invitations(@RequestBody Invitations invitations, HttpSession session) {
        log.info("发布邀请函:"+invitations);
        return invitationsService.post(invitations,session);
    }
    /* 用户已登录
       查看邀请函*/
    @GetMapping
    public Result application(HttpSession session) {

        return invitationsService.list(session);
    }

    /* 用户已登录
           报名*/
    @PostMapping("/addInfo")
    public Result applicationInv(@RequestBody Application application, HttpSession session) {
        log.info("报名:"+application);
        return invitationsService.checkAndAdd(application,session);
    }

    /* 未登录
       查看邀请函*/
    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id) {
        List<Invitations> invitationsList = invitationsService.selectById(id);
        log.info("根据id查看邀请函:"+invitationsList);
        return Result.success(invitationsList);
    }
}
